'use strict';

const Controller = require('egg').Controller;
class SystemPermissionController extends Controller {
    async getUserRoles() {
        const { ctx } = this;
        const { userId } = ctx.query;
        const result = await this.service.systemPermission.getUserRoles(userId);
        this.ctx.success(result);
    }

    async updateUserRoles() {
        const { ctx } = this;
        const {
            userId,
            roleIds,
        } = ctx.request.body;
        const result = await this.service.systemPermission.updateUserRoles(userId, roleIds);
        this.ctx.success(result);
    }
    async listRoleMenus() {
        const { ctx } = this;
        const { roleId } = ctx.query;
        const result = await this.service.systemPermission.listRoleMenus(roleId);
        this.ctx.success(result);
    }
    async updateRoleMenus() {
        const { ctx } = this;
        const {
            roleId,
            menuIds,
        } = ctx.request.body;
        const result = await this.service.systemPermission.updateRoleMenus(roleId, menuIds);
        this.ctx.success(result);
    }
}

module.exports = SystemPermissionController;
